$import("meta.metaHelper");
function initAttrPropPanel(region){
	var list=metaHelper.getAttrFields(metaId),
	booleanStore=new Ext.data.ArrayStore({
	    fields: [
		            'SID',
		            'TEXT'
		        ],
		        data: [
		            ["true", 'true'],
	             ["false", 'false']
	         ]	
	});
	var propertyNames={},source={},customEditors={};
	Ext.each(list,function(n,i){
		var key=n["name"];
		propertyNames[key]=n["text"];
		source[key]='';
		var type=n["type"];
		if(type==16){
			customEditors[key]=new Ext.grid.GridEditor(new Ext.form.ComboBox({typeAhead:true, triggerAction:'all', mode: 'local',store:booleanStore,valueField:"SID",displayField:"TEXT"}));
		}else if(type==1){
			customEditors[key]=new Ext.grid.GridEditor(new Ext.form.TextField({selectOnFocus:true}));
		}else if(type=="97"){
			customEditors[key]=new Ext.grid.GridEditor(new Ext.form.DateField());
		}else{
			customEditors[key]=new Ext.grid.GridEditor(new Ext.form.NumberField());
		}
	});
	var tbar=[{text:'保存',iconCls:'icon-submit',handler:function(){
		var attrGrid=Ext.getCmp('attrGrid');
		var source2=attrGrid.getSource();
		metaHelper.saveAttrMap(metaId,sid,source2,function(){
			attrGrid["source"]=source2;
			Ext.Msg.alert('提示','保存成功');
		});
		}},{text:'刷新',iconCls:'icon-reload',handler:function(){
			Ext.getCmp('attrGrid').loadData();
		}}];
	var propsGrid = new Ext.grid.PropertyGrid({
        tbar:tbar,
        id:"attrGrid",
        clicksToEdit:1,
        split:true,
        customEditors:customEditors,
        region:region,
        propertyNames: propertyNames,
        source: source,
        viewConfig : {
            forceFit: true
        },
        
        listners:{
        	'cellclick' : function(grid, rowIndex, columnIndex, e) {  
        	    return true;
        	}  
        }
    });
	propsGrid.loadData=function(){
		var data=metaHelper.getAttrMap(metaId,sid);
		Ext.applyIf(data,source);
		propsGrid["source"]=data;
		propsGrid.setSource(data);
	};
	propsGrid.setAutoScroll(true);
	return propsGrid;
}

Ext.onReady(function(){
	Ext.QuickTips.init();
	var propsGrid=initAttrPropPanel('center');
	new Ext.Viewport({
        width: 900,
        layout:'border',
        renderTo: 'container4',
        items:propsGrid
	});
	propsGrid.loadData();
});
